package model

import (
	"time"
	"strings"
)

type JueJinTime time.Time

const isoDateTimeLayout = "2006-01-02T15:04:05.000Z"

func (j *JueJinTime) UnmarshalJSON(b []byte) error {
	s := strings.Trim(string(b), "\"")
	t, err := time.Parse(isoDateTimeLayout, s)
	if err != nil {
		t, err = time.Parse("2006-01-02T15:04:05.Z", s)
	}
	*j = JueJinTime(t)
	return err
}

type News struct {
	Created time.Time
	Title   string
	Url     string
	Source  string
	Uuid    string
}

type JueJinModel struct {
	S int    `json:"s"`
	M string `json:"m"`
	D struct {
		Total int `json:"total"`
		Entrylist []struct {
			CollectionCount  int     `json:"collectionCount"`
			CommentsCount    int     `json:"commentsCount"`
			Gfw              bool    `json:"gfw"`
			ObjectID         string  `json:"objectId"`
			CheckStatus      bool    `json:"checkStatus"`
			BuildTime        float64 `json:"buildTime"`
			EntryView        string  `json:"entryView"`
			SubscribersCount int     `json:"subscribersCount"`
			NgxCachedTime    int     `json:"ngxCachedTime"`
			VerifyStatus     bool    `json:"verifyStatus"`
			Tags []struct {
				NgxCachedTime int    `json:"ngxCachedTime"`
				NgxCached     bool   `json:"ngxCached"`
				Title         string `json:"title"`
				ID            string `json:"id"`
			} `json:"tags"`
			IsEvent         bool       `json:"isEvent"`
			RankIndex       float64    `json:"rankIndex"`
			Hot             bool       `json:"hot"`
			UpdatedAt       JueJinTime `json:"updatedAt"`
			OriginalURL     string     `json:"originalUrl"`
			VerifyCreatedAt JueJinTime `json:"verifyCreatedAt"`
			CreatedAt       JueJinTime `json:"createdAt"`
			User struct {
				Community struct {
					Github struct {
						Company     string `json:"company"`
						UID         string `json:"uid"`
						BlogAddress string `json:"blogAddress"`
						Username    string `json:"username"`
						AvatarLarge string `json:"avatarLarge"`
					} `json:"github"`
					Wechat struct {
						AvatarURL string `json:"avatar_url"`
						UID       string `json:"uid"`
						Nickname  string `json:"nickname"`
					} `json:"wechat"`
				} `json:"community"`
				CollectedEntriesCount int    `json:"collectedEntriesCount"`
				Company               string `json:"company"`
				FollowersCount        int    `json:"followersCount"`
				FolloweesCount        int    `json:"followeesCount"`
				Role                  string `json:"role"`
				PostedPostsCount      int    `json:"postedPostsCount"`
				IsAuthor              bool   `json:"isAuthor"`
				PostedEntriesCount    int    `json:"postedEntriesCount"`
				TotalCommentsCount    int    `json:"totalCommentsCount"`
				NgxCachedTime         int    `json:"ngxCachedTime"`
				NgxCached             bool   `json:"ngxCached"`
				ViewedEntriesCount    int    `json:"viewedEntriesCount"`
				JobTitle              string `json:"jobTitle"`
				SubscribedTagsCount   int    `json:"subscribedTagsCount"`
				TotalCollectionsCount int    `json:"totalCollectionsCount"`
				Username              string `json:"username"`
				AvatarLarge           string `json:"avatarLarge"`
				ObjectID              string `json:"objectId"`
			} `json:"user"`
			Author          string      `json:"author"`
			Screenshot      interface{} `json:"screenshot"`
			Original        bool        `json:"original"`
			HotIndex        float64     `json:"hotIndex"`
			Content         string      `json:"content"`
			Title           string      `json:"title"`
			LastCommentTime string      `json:"lastCommentTime"`
			Type            string      `json:"type"`
			English         bool        `json:"english"`
			Category struct {
				NgxCached     bool   `json:"ngxCached"`
				Title         string `json:"title"`
				ID            string `json:"id"`
				Name          string `json:"name"`
				NgxCachedTime int    `json:"ngxCachedTime"`
			} `json:"category"`
			ViewsCount  int    `json:"viewsCount"`
			SummaryInfo string `json:"summaryInfo"`
			IsCollected bool   `json:"isCollected"`
		} `json:"entrylist"`
	} `json:"d"`
}
